package com.example.firstdemo.ui.screens.pages.addProblem.addProblemDetail

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.firstdemo.network.api.addProblem.AddProblemApi
import com.example.firstdemo.network.api.problem.ProblemApi
import com.example.firstdemo.ui.screens.pages.addProblem.addProblemDetail.data.AddProblemDetailUIState
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch

class AddProblemDetailViewModel : ViewModel() {
    private val _uiState = MutableStateFlow(AddProblemDetailUIState())
    val uiState: StateFlow<AddProblemDetailUIState> = _uiState

    fun getAddProblemDetail(passTime: String, uid: String, stationName: String) {
        viewModelScope.launch {
            try {
                val problem = AddProblemApi.getDetail(passTime, uid).data!!
                _uiState.value = _uiState.value.copy(
                    problem = problem,
                    stationName = stationName
                )
            } catch (_: Exception) {
            }
        }
    }
}